home *** CD-ROM | disk | FTP | other *** search
/ Treccani Italiana Di Scienze Lettere Ed Arti / [Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso / pc / data / xxi_appendice_dvd.swf / scripts / __Packages / CScrollableMenu.as < prev    next >
Text File  |  2007-11-08  |  6KB  |  146 lines

  1. class CScrollableMenu extends mx.core.UIObject
  2. {
  3.    function CScrollableMenu()
  4.    {
  5.       super();
  6.       this.mMaxItemNumber = 5;
  7.       this.mRowHeigth = 26;
  8.       this.mWidth = this._width;
  9.       this.mRect = new Object({left:this._x,top:this._y,right:this._x + this._width,bottom:this._y + this._height});
  10.       this.mType = "pullDown";
  11.       this.mShowGrabRect = false;
  12.       this._xscale = this._yscale = 100;
  13.       this.Hide();
  14.       this.doLater(this,"init");
  15.    }
  16.    function init()
  17.    {
  18.       this.mc_Background._x = 0;
  19.       this.mc_Background._y = 0;
  20.       this.mc_Background._height = this.mRowHeigth;
  21.       this.SetWidth(this.mWidth);
  22.       this.mc_MenuListbox.__set__rowHeight(this.mRowHeigth);
  23.       this.mc_MenuListbox.setStyle("borderStyle","none");
  24.       this.mc_MenuListbox.setStyle("borderColor",12566711);
  25.       this.mc_MenuListbox.embedFonts = _global.gUseEmbeddedFont;
  26.       this.mc_MenuListbox.setStyle("backgroundColor",7174258);
  27.       this.mc_MenuListbox.setStyle("rollOverColor",10398115);
  28.       this.mc_MenuListbox.setStyle("selectionColor",9477012);
  29.       this.mc_MenuListbox.setStyle("color",16777215);
  30.       this.mc_MenuListbox.setStyle("textRollOverColor",16777215);
  31.       this.mc_MenuListbox.setStyle("textSelectedColor",16777215);
  32.       this.mc_MenuListbox.addEventListener("change",mx.utils.Delegate.create(this,this.onItemSelected));
  33.       this.mc_ButtonUp.addEventListener("click",mx.utils.Delegate.create(this,this.onScrollUp));
  34.       this.mc_ButtonDown.addEventListener("click",mx.utils.Delegate.create(this,this.onScrollDown));
  35.       this.mc_GrabRect.onPress = mx.utils.Delegate.create(this,this.Hide);
  36.       this.mc_MenuListbox.__set__vScrollPolicy("off");
  37.    }
  38.    function SetWidth(inW)
  39.    {
  40.       this.mWidth = inW;
  41.       this.mc_Background._width = this.mWidth;
  42.       this.mc_ButtonUp.setSize(this.mWidth,this.mRowHeigth - 1);
  43.       this.mc_ButtonDown.setSize(this.mWidth,this.mRowHeigth - 1);
  44.       this.mc_MenuListbox.setSize(this.mWidth,this.mRowHeigth);
  45.    }
  46.    function setIconFunction(inFunction)
  47.    {
  48.       this.mc_MenuListbox.setIconFunction(inFunction);
  49.    }
  50.    function setCellRenderer(inRenderer, embeddedFont)
  51.    {
  52.       this.mc_MenuListbox.embedFonts = embeddedFont;
  53.       this.mc_MenuListbox.setCellRenderer(inRenderer);
  54.    }
  55.    function onScrollUp(evtObj)
  56.    {
  57.       var _loc2_ = this.mc_MenuListbox.__get__vPosition() - 1;
  58.       this.mc_MenuListbox.__set__vPosition(_loc2_);
  59.       this.mc_ButtonUp.enabled = _loc2_ > 0;
  60.       this.mc_ButtonDown.enabled = _loc2_ < this.mc_MenuListbox.length - this.mc_MenuListbox.__get__rowCount();
  61.    }
  62.    function onScrollDown(evtObj)
  63.    {
  64.       var _loc2_ = this.mc_MenuListbox.__get__vPosition() + 1;
  65.       this.mc_MenuListbox.__set__vPosition(_loc2_);
  66.       this.mc_ButtonUp.enabled = _loc2_ > 0;
  67.       this.mc_ButtonDown.enabled = _loc2_ < this.mc_MenuListbox.length - this.mc_MenuListbox.__get__rowCount();
  68.    }
  69.    function onItemSelected(evtObj)
  70.    {
  71.       this.Hide();
  72.       var _loc2_ = evtObj.target;
  73.       var _loc3_ = _loc2_.dataProvider.getItemAt(_loc2_.selectedIndex);
  74.       this.dispatchEvent({type:"scrollableMenuItemSelected",target:this,data:_loc3_,selectedItemIndex:_loc2_.selectedIndex});
  75.    }
  76.    function Show(inRecordset, inSelected)
  77.    {
  78.       var _loc3_ = Math.min(inRecordset.length,this.mMaxItemNumber);
  79.       this.mc_MenuListbox.__set__rowCount(_loc3_);
  80.       this.mc_MenuListbox.dataProvider = inRecordset;
  81.       if(inRecordset.length > this.mMaxItemNumber)
  82.       {
  83.          this.mc_ButtonUp._y = 1;
  84.          this.mc_MenuListbox._y = this.mc_ButtonUp._y + this.mc_ButtonUp.__get__height();
  85.          this.mc_ButtonDown._y = this.mc_MenuListbox._y + this.mc_MenuListbox.__get__height() + 1;
  86.          this.mc_Background._height = this.mc_ButtonDown._y + this.mc_ButtonDown.__get__height() + 1;
  87.          this.mc_ButtonUp._visible = true;
  88.          this.mc_ButtonDown._visible = true;
  89.          this.mc_ButtonUp.enabled = false;
  90.          this.mc_ButtonDown.enabled = true;
  91.       }
  92.       else
  93.       {
  94.          this.mc_Background._height = this.mc_MenuListbox.__get__height() + 1;
  95.          this.mc_ButtonUp._visible = false;
  96.          this.mc_ButtonDown._visible = false;
  97.          this.mc_MenuListbox._y = 0;
  98.       }
  99.       if(inSelected >= 0)
  100.       {
  101.          this.mc_MenuListbox.selectedIndex = inSelected;
  102.       }
  103.       if(this.mType == "pullDown")
  104.       {
  105.          this._y = this.mRect.top;
  106.       }
  107.       else
  108.       {
  109.          this._y = this.mRect.bottom - this.mc_Background._height;
  110.       }
  111.       this.mc_Background._visible = true;
  112.       this.mc_MenuListbox._visible = true;
  113.       if(this.mShowGrabRect)
  114.       {
  115.          this.InitGrabRect(this.mc_GrabRect);
  116.          this.mc_GrabRect._visible = true;
  117.       }
  118.       this._visible = true;
  119.    }
  120.    function Hide()
  121.    {
  122.       this.mc_GrabRect._visible = false;
  123.       this.mc_ButtonUp._visible = false;
  124.       this.mc_ButtonDown._visible = false;
  125.       this.mc_MenuListbox._visible = false;
  126.       this.mc_Background._visible = false;
  127.       this._visible = false;
  128.    }
  129.    function ReleaseMemory()
  130.    {
  131.       this.Hide();
  132.    }
  133.    function InitGrabRect(inClip)
  134.    {
  135.       var _loc2_ = {x:0,y:0};
  136.       inClip._xscale = inClip._yscale = 100;
  137.       inClip._x = inClip._y = 0;
  138.       inClip.globalToLocal(_loc2_);
  139.       inClip._x = _loc2_.x;
  140.       inClip._y = _loc2_.y;
  141.       inClip._width = Stage.width;
  142.       inClip._height = Stage.height;
  143.       inClip.useHandCursor = false;
  144.    }
  145. }
  146.